<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/aui.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <link rel="stylesheet" type="text/css" href="./css/aui-slide.css" />
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/api.js"></script>
    <script type="text/javascript" src="./script/doT.min.js"></script>
    <script type="text/javascript" src="./script/jquery.min.js"></script>
    <script type="text/javascript" src="./script/jquery-3.2.0.js"></script>
</head>
<body>
    <header class="aui-bar aui-bar-nav">
        <a class="aui-pull-left" onclick="closeWin()">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title">累计收益</div>
    </header>
    <div class="aui-bar-nav-d"></div>


    <div class="user-profit">
        <div id="list">
<!--             <dl>
                <dt>随意享收益<span>+1.11</span></dt>
                <dd>2018-06-07<span>3349.75</span></dd>
            </dl>
            <dl>
                <dt>随意享收益<span>+1.11</span></dt>
                <dd>2018-06-07<span>3349.75</span></dd>
            </dl>
            <dl>
                <dt>随意享收益<span>+1.11</span></dt>
                <dd>2018-06-07<span>3349.75</span></dd>
            </dl>
            <dl>
                <dt>随意享收益<span>+1.11</span></dt>
                <dd>2018-06-07<span>3349.75</span></dd>
            </dl> -->
        </div>
    </div>
</body>
<script type="text/template" id="template">
    {{~it:value:index}}
    <dl>
        <dt>{{=value.title}}<span>+{{=value.money}}</span></dt>
        <dd>{{=value.create_time}}<span>{{=value.account_money}}</span></dd>
    </dl>
    {{~}}
</script>
<script type="text/javascript">

    apiready = function(){
        updateData();
        // 下拉刷新
        pullRefresh();
        // 上拉加载
        pullLoading();
    };

    // 更新数据,模板函数
    function updateData(more){

        // 进度提示款
        api.showProgress({
            title: '努力加载中...',
            text: '先喝杯茶...',
            modal: false
        });
        var userid = $api.getStorage('userid');
        
        if (more)    {
            p += 1;
        }else {
            p = 1;
        }
        api.ajax({
            url: webAddress + '/index.php?ctl=app_user_center2&act=rate_list&p=' + p,
            method: 'post',
            data: {
                values: {
                    id: userid,
                },
            }
        },function(ret, err){
            // alert($api.jsonToStr(ret));
            if (ret) {
                // 关闭下拉刷新控件
                api.refreshHeaderLoadDone();
                api.hideProgress();
                if (ret.status == 0) {
                    alert(ret.info);
                    return false;
                }else{  
                    var data = ret.list;
                    // // 总资产
                    // var total_money = outputmoney(ret.user.total_money);
                    // data.total_money = total_money;
                    // $api.setStorage('total_money', total_money);
                    // // 可用余额
                    // var money = outputmoney(ret.user.money);
                    // data.money = money;
                    // $api.setStorage('money', money);
                    // // 已获收益
                    // var load_pay_earnings = outputmoney(ret.user.load_pay_earnings);
                    // data.load_pay_earnings = load_pay_earnings;
                    // // 待获收益
                    // var load_wait_earnings = outputmoney(ret.user.load_wait_earnings);
                    // data.load_wait_earnings = load_wait_earnings;
                    // // 冻结资金(待收本金)
                    // var lock_money = outputmoney(ret.user.lock_money);
                    // data.lock_money = lock_money;

                    // var list = ret.list;
                    // // 时间戳转换为时间 
                    // // for (var i = 0; i < list.length; i++) { 
                    // //     list[i].create_time = getDate(list[i].create_time)  ;
                    // // }
                    // 调用模板函数
                    templateFun(data);
                }
            } else {
                alert(err.msg);
                api.refreshHeaderLoadDone();
                api.hideProgress();
            }
        });
    };

    // 模板赋值函数
    function templateFun(data){
        var template = $api.byId('template');
        var dotFn = doT.template(template.innerHTML);
        var html = dotFn(data);
        var user = $api.byId('list');
        if (p == 1) {
            $api.html(user, html);
        }else{
            if (list=='') {
                api.toast({
                    msg: '没有更多了..',
                    duration: 2000,
                    location: 'bottom'
                });
                return;
            }
            $api.append(user, html);
        }
    }

    // 下拉刷新
    function pullRefresh(){
        api.setRefreshHeaderInfo({
            // loadingImg: 'widget://image/refresh.png',
            bgColor: '#ccc',
            textColor: '#fff',
            textDown: '下拉刷新...',
            textUp: '松开刷新...'
        }, function(ret, err) {
            //在这里从服务器加载数据，加载完成后调用api.refreshHeaderLoadDone()方法恢复组件到默认状态
            updateData();
        });
    }

    // 上拉加载
    function pullLoading(){
        api.addEventListener({
            name: 'scrolltobottom',
            extra: {
                threshold: 0
            }
        }, function(ret, err){
            updateData(true);
        });
    }

    function closeWin(){
        var setSele = 'randomSwitchBtn(2);';
        api.execScript({
            name: 'root',
            script: setSele,
        });
        api.closeToWin({
            name: 'root'
        });
    }
</script>
</html>